package com.bush.mall.coupon.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;
import com.bush.mall.common.entity.Result;;
import com.bush.mall.coupon.entity.CouponEntity;
import com.bush.mall.coupon.service.CouponService;
import javax.annotation.Resource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 优惠券信息
 * @author RUN
 * @date 2022-11-29
 */
@RestController
@RequestMapping("coupon/coupon")
@Api(tags = "优惠券信息管理" )
public class CouponController {

    @Resource(name= CouponService.BEAN_ID)
    private CouponService couponService;


    /**
     * 分页查询会员的优惠券
     * @author RUN
     * @date 2022-11-29
     */
    @ApiOperation(value = "分页查询优惠券信息列表")
    @GetMapping("member/list")
    public Result memberCoupon(){
        JSONObject params = new JSONObject();
        params.put("message","I Love Sy");
        params.put("name","Bush");
        return Result.ok(params);
    }

    /**
     * 分页查询优惠券信息列表
     * @author RUN
     * @date 2022-11-29
     */
    @ApiOperation(value = "分页查询优惠券信息列表")
    @GetMapping("queryForPage")
    public Result queryForPage(Integer current,Integer size){
        return couponService.queryForPage(current,size);
    }

    /**
     * 保存优惠券信息表单
     * @author RUN
     * @date 2022-11-29
     */
    @ApiOperation(value = "保存优惠券信息表单")
    @PostMapping
    public Result saveCoupon(@RequestBody CouponEntity coupon){
        return couponService.saveCoupon(coupon);
    }

    /**
     * 修改优惠券信息表单
     * @author RUN
     * @date 2022-11-29
     */
    @ApiOperation(value = "修改优惠券信息表单")
    @PutMapping
    public Result updateCoupon(@RequestBody CouponEntity coupon){
        return couponService.updateCoupon(coupon);
    }

    /**
     * 通过指定id删除优惠券信息
     * @author RUN
     * @date 2022-11-29
     */
    @ApiOperation(value = "通过指定id删除优惠券信息")
    @DeleteMapping
    public Result deleteCoupon(Long id){
        return couponService.deleteCoupon(id);
    }

}
